package jjn.offer_round2;

import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/17 19:07
 */
public class Offer44 {
    public int findNthDigit(int n) {
        int digit = 1;
        long start = 1;
        long count = 9;
        while (n > count) {
            n -= (int) count;
            digit += 1;
            start *= 10;
            count = digit * start * 9;
        }
        long num = start + (n - 1) / digit;
        return Long.toString(num).charAt((n - 1) % digit) - '0';
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int nthDigit = new Offer44().findNthDigit(scanner.nextInt());
        System.out.println(nthDigit);
    }
}
